home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / CubePyramidDemo.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  8.5 KB  |  211 lines

  1. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  2. ' Cube and pyramid demo
  3.  
  4. ' Modified from nehe's tutorial 5.
  5.  
  6. dim frames, timer, fps
  7. dim texture, groundTex, skyTex (4)
  8. texture         = LoadMipmapTexture ("textures\00003.jpg")
  9. groundTex         = LoadMipmapTexture ("textures\00006.jpg")
  10. skyTex (0)     = LoadMipmapTexture ("textures\t003.jpg")
  11. skyTex (1)     = LoadMipmapTexture ("textures\l003.jpg")
  12. skyTex (2)     = LoadMipmapTexture ("textures\f003.jpg")
  13. skyTex (3)     = LoadMipmapTexture ("textures\r003.jpg")
  14. skyTex (4)     = LoadMipmapTexture ("textures\b003.jpg")
  15.  
  16. resizetext (30, 21)
  17. textmode (TEXT_OVERLAID)
  18. dim x, y, ang#, sep#, a$, i: sep# = 90
  19. y = textrows () / 2 - 2
  20. a$ = "Cube": gosub msg
  21. y = y + 1: a$ = "and": gosub msg
  22. y = y + 1: a$ = "Pyramid": gosub msg
  23.  
  24. glEnable (GL_CULL_FACE)
  25.  
  26. while true
  27.     glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
  28.  
  29.     ' Sky box
  30.     glDisable (GL_DEPTH_TEST)
  31.     glDisable (GL_CULL_FACE)
  32.     glEnable (GL_TEXTURE_2D)
  33.     glColor3f (1, 1, 1)
  34.     glMatrixMode (GL_MODELVIEW)
  35.     glLoadIdentity ()
  36. '    glTranslatef (0, -1, 0)
  37.     glRotatef (ang#, 0, 1, 0)
  38.     glPushMatrix ()
  39.     
  40.     ' Top
  41.     glBindTexture (GL_TEXTURE_2D, skyTex (0))
  42.     glBegin (GL_QUADS)
  43.         glTexCoord2f (0, 0): glVertex3f (-2.05, 2, -2.05)
  44.         glTexCoord2f (0, 1): glVertex3f ( 2.05, 2, -2.05)
  45.         glTexCoord2f (1, 1): glVertex3f ( 2.05, 2,  2.05)
  46.         glTexCoord2f (1, 0): glVertex3f (-2.05, 2,  2.05)
  47.     glEnd ()
  48.  
  49.     ' Sides
  50.     for i = 1 to 4
  51.         glBindTexture (GL_TEXTURE_2D, skyTex (i))
  52.         glBegin (GL_QUADS)
  53.             glTexCoord2f (1, 1): glVertex3f (-2.05, 2.05, -2)
  54.             glTexCoord2f (0, 1): glVertex3f ( 2.05, 2.05, -2)
  55.             glTexCoord2f (0, 0): glVertex3f ( 2.05,-0.05, -2)
  56.             glTexCoord2f (1, 0): glVertex3f (-2.05,-0.05, -2)
  57.         glEnd ()
  58.         glRotatef (90, 0, 1, 0)
  59.     next        
  60.  
  61.     ' Ground
  62.     glPopMatrix ()
  63.     glTranslatef (0, -1, 0)
  64.     glBindTexture (GL_TEXTURE_2D, groundTex)
  65.     glBegin (GL_QUADS)
  66.         glTexCoord2f (0,  0): glVertex3f (-20, 0, 20)
  67.         glTexCoord2f (16, 0): glVertex3f ( 20, 0, 20)
  68.         glTexCoord2f (16, 16): glVertex3f ( 20, 0,-20)
  69.         glTexCoord2f (0,  16): glVertex3f (-20, 0,-20)
  70.     glEnd ()
  71.  
  72.     glEnable (GL_DEPTH_TEST)
  73.     glEnable (GL_CULL_FACE)
  74.  
  75.     glMatrixMode (GL_MODELVIEW)
  76.     glLoadIdentity ()
  77.     glTranslatef (0, 0, -10)    
  78.     glRotatef (ang#, 0, 1, 0)
  79.     glTranslatef (-20, -sin (sep#) * 4, -20)
  80.     glCullFace (GL_BACK)
  81.     gosub scene
  82.  
  83.     glLoadIdentity ()
  84.     glTranslatef (0, 0, -10)    
  85.     glRotatef (-ang#, 0, 1, 0)
  86.     glScalef (1, -1, 1)
  87.     glTranslatef (-20, -sin (sep#) * 4, -20)
  88.     glCullFace (GL_FRONT)
  89.     gosub scene
  90.  
  91.     frames = frames + 1
  92.     locate 0, 0: print fps + "   "
  93.  
  94.     DrawText ()
  95.     SwapBuffers ()
  96.  
  97.     if frames >= 100 then 
  98.         fps = Int (frames / ((TickCount () - timer) / 1000.0))
  99.         frames = 0
  100.         timer = TickCount ()
  101.     endif
  102.  
  103.     while SyncTimer (10)
  104.         gosub Animate
  105.     wend
  106. wend
  107. end
  108.  
  109. scene:
  110.     for y = 0 to 10
  111.         glPushMatrix ()
  112.         for x = 0 to 10
  113.             if (x+y)%2 = 0 then 
  114.                 gosub pyramid
  115.             else
  116.                 gosub cube
  117.             endif
  118.             glTranslatef (4, 0, 0)
  119.         next
  120.         glPopMatrix ()
  121.         glTranslatef (0, 0, 4)
  122.     next
  123.     return        
  124.  
  125.  
  126. pyramid:
  127.     glDisable (GL_TEXTURE_2D)
  128.         glBegin(GL_TRIANGLES)                        ' Drawing using triangles
  129.                     glColor3f(1.0,0.0,0.0)                  ' Red
  130.             glVertex3f( 0.0, 1.0, 0.0)            ' Top of triangle (front)
  131.             glColor3f(0.0,1.0,0.0)                ' Green
  132.             glVertex3f(-1.0,-1.0, 1.0)            ' Left of triangle (front)
  133.             glColor3f(0.0,0.0,1.0)                ' Blue
  134.             glVertex3f( 1.0,-1.0, 1.0)            ' Right of triangle (front)
  135.  
  136.                     glColor3f(1.0,0.0,0.0)                ' Red
  137.             glVertex3f( 0.0, 1.0, 0.0)            ' Top of triangle (right)
  138.             glColor3f(0.0,0.0,1.0)                ' Blue
  139.             glVertex3f( 1.0,-1.0, 1.0)            ' Left of triangle (right)
  140.             glColor3f(0.0,1.0,0.0)                ' Green
  141.             glVertex3f( 1.0,-1.0, -1.0)            ' Right of triangle (right)
  142.  
  143.                     glColor3f(1.0,0.0,0.0)                ' Red
  144.             glVertex3f( 0.0, 1.0, 0.0)            ' Top of triangle (back)
  145.             glColor3f(0.0,1.0,0.0)                ' Green
  146.             glVertex3f( 1.0,-1.0, -1.0)            ' Left of triangle (back)
  147.             glColor3f(0.0,0.0,1.0)                ' Blue
  148.                     glVertex3f(-1.0,-1.0, -1.0)            ' Right of triangle (back)
  149.  
  150.                     glColor3f(1.0,0.0,0.0)                ' Red
  151.             glVertex3f( 0.0, 1.0, 0.0)            ' Top of triangle (left)
  152.             glColor3f(0.0,0.0,1.0)                ' Blue
  153.             glVertex3f(-1.0,-1.0,-1.0)            ' Left of triangle (left)
  154.             glColor3f(0.0,1.0,0.0)                ' Green
  155.             glVertex3f(-1.0,-1.0, 1.0)            ' Right of triangle (left)
  156.         glEnd()                            ' Finished Drawing The Triangle
  157.         return
  158.  
  159. cube:
  160.         glEnable (GL_TEXTURE_2D)
  161.         glBindTexture (GL_TEXTURE_2D, texture)
  162.         glBegin(GL_QUADS)                        ' Draw a quad
  163.             glColor3f(0.0,1.0,0.0)                ' Set the color to green
  164.             glTexCoord2f(0,0):glVertex3f( 1.0, 1.0,-1.0)            ' Top right of the quad (top)
  165.             glTexCoord2f(1,0):glVertex3f(-1.0, 1.0,-1.0)            ' Top left of the quad (top)
  166.             glTexCoord2f(1,1):glVertex3f(-1.0, 1.0, 1.0)            ' Bottom left of the quad (top)
  167.             glTexCoord2f(0,1):glVertex3f( 1.0, 1.0, 1.0)            ' Bottom right of the quad (top)
  168.                     glColor3f(1.0,0.5,0.0)                ' Set the color to orange
  169.             glTexCoord2f(0,0):glVertex3f( 1.0,-1.0, 1.0)            ' Top right of the quad (bottom)
  170.             glTexCoord2f(1,0):glVertex3f(-1.0,-1.0, 1.0)            ' Top left of the quad (bottom)
  171.             glTexCoord2f(1,1):glVertex3f(-1.0,-1.0,-1.0)            ' Bottom left of the quad (bottom)
  172.             glTexCoord2f(0,1):glVertex3f( 1.0,-1.0,-1.0)            ' Bottom right of the quad (bottom)
  173.  
  174.                     glColor3f(1.0,0.0,0.0)                ' Set the color to red
  175.             glTexCoord2f(0,0):glVertex3f( 1.0, 1.0, 1.0)            ' Top right of the quad (front)
  176.             glTexCoord2f(1,0):glVertex3f(-1.0, 1.0, 1.0)            ' Top left of the quad (front)
  177.             glTexCoord2f(1,1):glVertex3f(-1.0,-1.0, 1.0)            ' Bottom left of the quad (front)
  178.             glTexCoord2f(0,1):glVertex3f( 1.0,-1.0, 1.0)            ' Bottom right of the quad (front)
  179.  
  180.                     glColor3f(1.0,1.0,0.0)                ' Set the color to yellow
  181.             glTexCoord2f(0,0):glVertex3f( 1.0,-1.0,-1.0)            ' Bottom left of the quad (back)
  182.             glTexCoord2f(1,0):glVertex3f(-1.0,-1.0,-1.0)            ' Bottom right of the quad (back)
  183.             glTexCoord2f(1,1):glVertex3f(-1.0, 1.0,-1.0)            ' Top right of the quad (back)
  184.             glTexCoord2f(0,1):glVertex3f( 1.0, 1.0,-1.0)            ' Top left of the quad (back)
  185.  
  186.                     glColor3f(0.0,0.0,1.0)                  ' Set the color to blue
  187.             glTexCoord2f(0,0):glVertex3f(-1.0, 1.0, 1.0)            ' Top right of the quad (left)
  188.             glTexCoord2f(1,0):glVertex3f(-1.0, 1.0,-1.0)            ' Top left of the quad (left)
  189.             glTexCoord2f(1,1):glVertex3f(-1.0,-1.0,-1.0)            ' Bottom left of the quad (left)
  190.             glTexCoord2f(0,1):glVertex3f(-1.0,-1.0, 1.0)            ' Bottom right of the quad (left)
  191.  
  192.                     glColor3f(1.0,0.0,1.0)                ' Set the color to violet
  193.             glTexCoord2f(0,0):glVertex3f( 1.0, 1.0,-1.0)            ' Top right of the quad (right)
  194.             glTexCoord2f(1,0):glVertex3f( 1.0, 1.0, 1.0)            ' Top left of the quad (right)
  195.             glTexCoord2f(1,1):glVertex3f( 1.0,-1.0, 1.0)            ' Bottom left of the quad (right)
  196.             glTexCoord2f(0,1):glVertex3f( 1.0,-1.0,-1.0)            ' Bottom right of the quad (right)
  197.         glEnd()
  198.         return
  199.  
  200.  
  201. msg: 
  202.  
  203.     locate (TextCols () - len (a$)) / 2, y
  204.     print a$
  205.     y = y + 1
  206.     return    
  207.  
  208. Animate:
  209.     ang# = ang# + 0.3
  210. '    sep# = sep# + 0.02
  211.     return